package com.xcity.game.common;

import java.util.Random;

import com.xcity.db.entity.Build;

import naga.x.game.template.annotation.Excel;
import naga.x.util.CommonUtils;

@Excel(value = "global.xlsx", sheet = 0, isStatic = true)
public class GameStaticConfig {
	
	public static float robRatio = 0.2f; // 抢劫非好友比例
	public static float robFriendRatio = 0.025f; // 抢劫好友比例
	public static int speedUpExp = 2; // 建筑升级/建造时点击获得经验
//	@Deprecated
//	public static int speedUpCritChance = 2; // 点击暴击几率(百分比)
//	public static int speedUpCritExp = 10; // 暴击经验
	@Deprecated
	public static int speedUpReduceCD = 1000; // 点击建造减少cd时间(毫秒)
	public static int defaultChanceBase = 10000; // 概率基数
	public static int percentBase = 100; // 百分比基数
	public static int initGold = 0; // 新玩家初始金币数
	public static int initStone = 1;
	public static float beatBackDecStrRatio = 0.05f; // 反击扣体力5%
	public static int presentStr = 2; // 好友赠送体力点数
	public static int mealRewardStr = 50; // 每日午餐、晚餐奖励体力点数
	public static int mealRewardVigour = 100; // 每日午餐、晚餐奖励精力点数
	public static short fresherMaxGuide = 38; // 新手引导最大步数
	public static int strengthRecoveryValPerLvl = 25; // 人物升级时恢复体力点数
	
	public static final int TAP_LIKE_FRIEND_ADD_SELF_CHARM = 20; // 给好友点赞时自己增加20点魅力值
	public static final int TAP_LIKE_OTHER_ADD_SELF_CHARM = 10; // 给其他玩家点赞时给自己增加10点魅力值
	public static final int TAP_LIKE_ADD_TARGET_CHARM = 50; // 点赞给对方增加50点魅力值
	
	// 各系统开放等级限制
	/** 员工招聘开放等级 */ // @see menuOpen.xlsx#6
	public static int employeeRecruitOpenLvl = 1;
	/** 员工培养开放等级 */ // @see menuOpen.xls#200
	public static int employeeTrainOpenLvl = 1;
	/** 普通副本（拓展）开放等级 */ // @see menuOpen.xls#9
	public static int pveStageOpenLvl = 1;
	/** 碎片拼图活动开放等级 */
	public static int chipsCollectActivityOpenLvl = 1;//2017.04.13:1级开放//15;
	/** 竞技场开放等级 */ // @see menuOpen.xls#12
	public static int arenaOpenLvl = 18;
	/** 装备强化开放等级 */ // @see menuOpen.xls#100
	public static int equipEnhanceOpenLvl = 16;
	/** 领取体力开放等级 */
	public static int strengthMealActivityOpenLvl = 15;
	
	/** 资源副本开放等级 */
	public static int resStageOpenLvl = 10;
	/** 资源副本CD(分钟)*/
	public static int resStageCDMin = 5;
	
	/** 巅峰之路每日次数 */
	public static int peakRoadTimes = 2;
	/** 巅峰之路消耗体力 */
	public static int peakRoadCostStr = 10;
	/** 巅峰银行刷新cd（秒） */
	public static int peakShopRefreshCD = 7200;
	/** 巅峰银行钻石刷新次数 */
	public static int peakShopRefreshTimes = 12;
	/** 巅峰银行首次刷新消耗钻石 */
	public static int peakShopRefreshCost = 10;
	/** 巅峰银行刷新钻石消耗递增数 */
	public static int peakShopRefreshCostDelta = 5;
	
	public static int addVigourValue = 1;//300秒恢复1点精力
	public static int addVigourGap = 300;//300秒恢复1点精力
	public static int restoreVigour = 100;//购买(恢复)精力
	public static int restoreStrength = 50;//每次购买(恢复)体力
	public static int restoreMoney = 50000;//购买现金
	@Deprecated
	public static int activityThirty_Moon = 0;
	@Deprecated
	public static int activityThirty_Year = 2000;
	
	/** 转一次奇遇获得经验 */
	public static int adventureExp = 10;
//	/** 玩家默认技能 */
//	public static int playerDefaultSkillId = 100002;
	/** 奇遇占领建筑功能开放等级 */
	public static int adventureCaptureFuncOpenLvl = 3;
	/** 奇遇占领建筑功能在第12格 */
	public static int adventureCaptureFuncPos = 11;
	/** 奇遇第一次攻占目标机器人id */
	public static int adventureFirstCaptureRobotId = 9001;
	/** 奇遇第一次攻占己方使用npc */
//	public static int[] adventureFirstCaptureSrcNpcs = new int[] { 9001, 9002, 9003, 9004 };
	
	//----招聘相关
	public static int recruitCostMoneyOne = 20000;//金币单抽价格
	public static int recruitCostMoneyTen = 180000;//金币十连价格
	public static int recruitCostMoneyHundred = 1800000;//金币百连
	public static int recruitCostStoneOne = 230;//钻石单抽价格
	public static int recruitCostStoneTen = 2070;//钻石十连
	public static int recruitCostStoneTenSequent = 1863;//连续钻石十连
	public static int recruitStoneDiscount = 5;//钻石每日首次五折
	public static int recruitStoneFreeCount = 1;//钻石每日免费次数
	public static int recruitMoneyFreeCount = 5;//金币每日免费次数
	public static int recruitMoneyCountLimit1 = 20;//金币1抽次数限制
	public static int recruitMoneyCountLimit10 = 20;//金币10抽次数限制
	public static int recruitMoneyCountLimit100 = 20;//金币100抽次数限制
	//----招聘相关结束
	
	//----探索地图相关
	public static int mineMaxTakeTime = 8;//最长占矿时间(小时)
	public static int mineLimitTimeStart = 2;//2~9点不能占矿
	public static int mineLimitTimeEnd = 9;//2~9点不能占矿
	//----探索地图相关结束
	
	public static int pvpWinRewardGold = 100000;
	public static int pvpLoseRewardGold = 30000;
	@Deprecated
	/** 最多可占领建筑数量 弃用  在recharge表控制了*/
	public static int captureBuildMaxCount = 40;
	/** 最多可占领同一好友建筑数量 */
	public static int captureSameFriendBuildMaxCount = 2;
	/** 技能点数上限 */
	public static int maxSkillPoints = 10;
	/** 技能点数恢复时间间隔（分钟） */
	public static int skillPointsRecoverInterval = 5;
	/** 技能点数每次恢复数量 */
	public static int skillPointsRecoverVal = 1;
	/** 每次可购买技能点数 */
	public static int skillPointsPerTimeBuy = 10;
	/** 员工重生返还比例 */
	public static float rebornReturnRatio = 0.8f;
	/** 员工重生钻石消耗递增量 */
	public static int rebornCostStoneDelta = 20;

	
	private GameStaticConfig() {}
	
	// 系统罚款概率配置
	public static SectionProb[] systemFines = new SectionProb[] {
		new SectionProb(100, 200, 1800),
		new SectionProb(200, 400, 2500),
		new SectionProb(400, 550, 3500),
		new SectionProb(550, 650, 5000),
		new SectionProb(650, 750, 6500),
		new SectionProb(750, 850, 7500),
		new SectionProb(850, 950, 8500),
		new SectionProb(950, Integer.MAX_VALUE, 9000),
	};
	
	// 宝箱掉落几率
	public static SectionProb[] treasureBox = new SectionProb[] {
//			收益区间:10%--39%，宝箱掉落:10%
			new SectionProb(10, 40, 1000),
//			40--79，宝箱掉落25%
			new SectionProb(40, 80, 2500),
//			80--100，宝箱掉落60%
			new SectionProb(80, 101, 6000)
	};
	
	// 区间概率
	public static class SectionProb {
		public final int minVal, maxVal; // 触发值区间[min, max)
		public final int probability; // 触发几率(万分比)
		private SectionProb(int minVal, int maxVal, int probability) {
			this.minVal = minVal;
			this.maxVal = maxVal;
			this.probability = probability;
		}
	}
	
	/**
	 * 尝试触发系统罚款
	 * 罚款金额:
	 * 金币: 总收益 * 0.5 * (0~1)
	 * 或
	 * 钻石: 金币 * 0.01
	 * @param risk
	 * @return
	 */
	public static boolean triggerSystemFine(int risk) {
		return triggerProb(CommonUtils.RND, systemFines, risk);
	}
	
	/**
	 * 触发宝箱掉落
	 * @param incomeRate 收益率
	 * @return
	 */
	public static boolean triggerTreasureBoxDrop(Random random, int incomeRate) {
		return triggerProb(random, treasureBox, incomeRate);
	}
	
	public static boolean triggerProb(Random random, SectionProb[] probs, int val) {
		if (val < probs[0].minVal) { // 触发值未达到最低值
			return false;
		}
		if (random == null) {
			random = CommonUtils.RND;
		}
		for (SectionProb sp : probs) {
			if (val >= sp.minVal && val < sp.maxVal) {
				return random.nextInt(defaultChanceBase) < sp.probability;
			}
		}
		return false;
	}
	
	/**
	 * 获取立即完成建造所需钻石(每150秒1钻,四舍五入)
	 * @param build
	 * @return
	 */
	public static int getFinishBuildCostStone(Build build) {
		int cd = build.getLeftCD();
		return (int) (cd < 150000 ? 1 : cd / 150000f + 0.5f);
	}
	
	public static int getClearBuildRestStateCostStone(Build build) {
		int cd = build.getLeftRestCD();
		return (int) (cd < 150000 ? 1 : cd / 150000f + 0.5f);
	}

}
